//
//  Contact_ReportTableViewCell.m
//  HuaRun2
//
//  Created by admin on 17/9/2.
//  Copyright © 2017年 Sunny. All rights reserved.
//

#import "Contact_ReportTableViewCell.h"
#import "LineView.h"
#import "CRCGroupFlagView.h"
#import "Contact_ReportModel.h"

@interface Contact_ReportTableViewCell ()

//名字
@property (nonatomic, strong) UILabel * nameLab;
//CRC Group
@property(nonatomic, strong)CRCGroupFlagView * crcFlagView;

//时区Btn
@property (nonatomic, strong) UIButton * timeBtn;
//时区Btn
@property (nonatomic, strong) UIButton * locationBtn;

//时区
@property (nonatomic, strong) UILabel * timeLab;
//时区 的下一行
@property (nonatomic, strong) UILabel * timeLab1;

//位置
@property (nonatomic, strong) UILabel * locationLab;
//位置的下一行
@property (nonatomic, strong) UILabel * locationLab1;

//分割线
@property (nonatomic, strong) LineView * lineView;
@end

@implementation Contact_ReportTableViewCell

#pragma mark - life cycle
- (void)dealloc {
    NSLog(@"%@ dealloc", [self class]);
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
//        self.contentView.backgroundColor = [UIColor whiteColor];// RGBA(249, 249, 249, 1);
//        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self viewInit];
        [self layoutInit];
    }
    return self;
}

- (void)viewInit {
    
    [super viewInit];
    
    [self.contentView addSubview:self.nameLab];
    [self.contentView addSubview:self.crcFlagView];

    [self.contentView addSubview:self.timeBtn];
    [self.contentView addSubview:self.timeLab];
    [self.contentView addSubview:self.timeLab1];
    
    [self.contentView addSubview:self.locationBtn];
    [self.contentView addSubview:self.locationLab];
    [self.contentView addSubview:self.locationLab1];
    
    [self.contentView addSubview:self.lineView];
}

- (void)setContact_ReportModel:(Contact_ReportModel *)contact_ReportModel {
    _contact_ReportModel = contact_ReportModel;

    _nameLab.text = [NSString stringWithFormat:@"%@ %@",
                     [self commonStringWithStr:contact_ReportModel.lastName],
                     [self commonStringWithStr:contact_ReportModel.firstName]
                     ];

    _timeLab.text = [self commonStringWithStr:contact_ReportModel.accountName];
    _timeLab1.text = [self commonStringWithStr:contact_ReportModel.nameChinese];
    
    _locationLab.text = [self commonStringWithStr:contact_ReportModel.title];
    _locationLab1.text = [self commonStringWithStr:contact_ReportModel.titleChinese];
    
    _crcFlagView.hidden = [contact_ReportModel.resigned intValue] == 0;
}

- (NSString *)commonStringWithStr:(NSString *)str {
    BOOL isEmpty = [NSString isemptyStr: str];
    return isEmpty ? @" " : str;
}

- (void)layoutInit {
    
    weakself(ws);
    [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(ws.contentView).offset(kMargin10);
        make.right.mas_equalTo(ws.contentView).offset(-kMargin10);
        make.top.mas_equalTo(ws.contentView).offset(kMargin10);
        make.bottom.mas_equalTo(ws.contentView).offset(-0);
    }];
    [self.nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(ws.backView.mas_left).offset(kMargin10);
        make.top.mas_equalTo(ws.backView).offset(kMargin10* 3);
        make.right.mas_equalTo(ws.crcFlagView.mas_left).offset(-kMargin10);
    }];

    [self.crcFlagView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(ws.backView).offset(-kMargin10);
        make.centerY.mas_equalTo(ws.nameLab).offset(0);
        
    }];
    
    [self.timeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(ws.nameLab.mas_bottom).offset(kMargin15);
//        make.top.mas_equalTo(ws.backView).offset(kMargin10 * 3);
        make.left.mas_equalTo(ws.backView.mas_left).offset(kMargin10);
        make.size.mas_equalTo(CGSizeMake(15, 15));
    }];
    
    [self.timeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(ws.timeBtn);
        make.left.mas_equalTo(ws.timeBtn.mas_right).offset(kMargin10);
        make.right.mas_equalTo(ws.backView.mas_right).offset(-kMargin10);
    }];
    
    [self.timeLab1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(ws.timeLab.mas_bottom);
        make.left.right.mas_equalTo(ws.timeLab).offset(0);
    }];
    
    [self.locationBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(ws.timeLab1.mas_bottom).offset(kMargin10/2);
        make.left.mas_equalTo(ws.timeBtn);
        make.size.mas_equalTo(ws.timeBtn);
    }];
    
    [self.locationLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(ws.locationBtn);
        make.left.mas_equalTo(ws.locationBtn.mas_right).offset(kMargin10);
        make.right.mas_equalTo(ws.backView.mas_right).offset(-kMargin10);
    }];
    
    [self.locationLab1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(ws.locationLab.mas_bottom);
        make.left.right.mas_equalTo(ws.locationLab).offset(0);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(ws.backView);
        make.left.mas_equalTo(ws.backView).offset(kMargin10);
        make.right.mas_equalTo(ws.locationLab).offset(0);
        make.height.mas_equalTo(1);
    }];
    
}


#pragma mark getter 


- (UILabel *)nameLab {
    if (!_nameLab) {
        self.nameLab = [UILabel new];
        _nameLab.textAlignment = NSTextAlignmentLeft;
        _nameLab.font = kGeneralFontSize;
        _nameLab.textColor = [UIColor colorWithHex:@"3c3c3c"];
    }
    return _nameLab;
}

- (UILabel *)timeLab {
    if (!_timeLab) {
        self.timeLab = [UILabel new];
        _timeLab.textAlignment = NSTextAlignmentLeft;
        _timeLab.font = kGeneralFontSize;
        _timeLab.textColor = [UIColor colorWithHex:@"3c3c3c"];
    }
    return _timeLab;
}

- (UILabel *)timeLab1 {
    if (!_timeLab1) {
        self.timeLab1 = [UILabel new];
        _timeLab1.textAlignment = NSTextAlignmentLeft;
        _timeLab1.font = kGeneralFontSize;
        _timeLab1.textColor = [UIColor colorWithHex:@"3c3c3c"];

    }
    return _timeLab1;
}

- (UILabel *)locationLab {
    if (!_locationLab) {
        self.locationLab = [UILabel new];
        _locationLab.textAlignment = NSTextAlignmentLeft;
        _locationLab.font = kGeneralFontSize;
        _locationLab.textColor = [UIColor colorWithHex:@"3c3c3c"];
//        _locationLab.text = @"0helloworld\nhelloworld\nhelloworld";
        //        _locationLab.numberOfLines = 2;
    }
    return _locationLab;
}

- (UILabel *)locationLab1 {
    if (!_locationLab1) {
        self.locationLab1 = [UILabel new];
        _locationLab1.textAlignment = NSTextAlignmentLeft;
        _locationLab1.font = kGeneralFontSize;
        _locationLab1.textColor = [UIColor colorWithHex:@"3c3c3c"];
//        _locationLab1.text = @"1helloworld\nhelloworld\nhelloworld";
        //        _locationLab.numberOfLines = 2;
    }
    return _locationLab1;
}

- (UIButton *)locationBtn {
    if (!_locationBtn) {
        self.locationBtn = [UIButton new];
        [_locationBtn setBackgroundImage:[UIImage imageNamed:@"gongsi_juese1"]
                                forState:(UIControlStateNormal)];
    }
    return _locationBtn;
}


- (UIButton *)timeBtn {
    if (!_timeBtn) {
        self.timeBtn = [UIButton new];
        [_timeBtn setBackgroundImage:[UIImage imageNamed:@"lianxiren_juese1"]
                            forState:(UIControlStateNormal)];
    }
    return _timeBtn;
}

- (LineView *)lineView {
    if (!_lineView) {
        self.lineView =  [LineView new];
    }
    return _lineView;
}

- (CRCGroupFlagView *)crcFlagView {
    if (!_crcFlagView) {
        self.crcFlagView = [CRCGroupFlagView new];
        _crcFlagView.imageSize = CGSizeMake(15, 15);
    }
    return _crcFlagView;
}
@end
